////
//// Created by enemy1205 on 2021/8/24.
////
//#Include "Armor.h"
//#Include <opencv4/opencv2/dnn.hpp>
//NumDetect::NumDetect(const Mat & armor) {
//    warpPerspective_mat = Mat(3, 3, CV_32FC1);
//    dstPoints[0] = Point2f(0, 0);
//    dstPoints[1] = Point2f(100, 0);
//    dstPoints[2] = Point2f(100,100);
//    dstPoints[3] = Point2f(0, 100);
//    cvtColor(armor,warpPerspective_src,COLOR_BGR2GRAY);
//}
//void NumDetect::getConfrontArmor(Armor_ptr &armor) {
//    srcPoints[0] = Point2f (0,0);
//    srcPoints[1]=armor->getVertexes()[2]-armor->getVertexes()[1];
//    srcPoints[2]=armor->getVertexes()[3]-armor->getVertexes()[1];
//    srcPoints[3]=armor->getVertexes()[0]-armor->getVertexes()[1];
//    //仿射变换得到正视装甲板图
//    warpPerspective_mat = getPerspectiveTransform(srcPoints, dstPoints);  //透射变换矩阵
//    warpPerspective(warpPerspective_src, warpPerspective_dst, warpPerspective_mat,Size(100,100), INTER_NEAREST,
//                    BORDER_CONSTANT, Scalar(0)); //仿射变换
//                    warpPerspective_dst.copyTo(armor->ConfrontImg); //获得正视图
//}
//void NumDetect::Detect(Mat &armor) {
//    dnn::Net net = dnn::readNetFromONNX(this->model_path);
//    CV_Assert(!net.empty());
//    net.setPreferableBackend(dnn::DNN_BACKEND_OPENCV);
//    net.setPreferableTarget(dnn::DNN_TARGET_CPU);
//    Mat input, prob;
//    input = dnn::blobFromImage(armor);
//    net.setInput(input);
//    net.forward(prob);
//    float sum = 0.f;
//    for (auto it = prob.begin<float>(); it != prob.end<float>(); it++) {
//        if ((*it) > 0)
//            sum += (*it);
//        else
//            (*it) = 0.f;
//    }
//    for (auto it = prob.begin<float>(); it != prob.end<float>(); it++) {
//        (*it) /= sum;
//    }
//    Point classIdPoint;
//    double confidence;
//    //查找最大值和最小值
//    minMaxLoc(prob.reshape(1, 1), 0, &confidence, 0, &classIdPoint);
//    int classId = classIdPoint.x;
//    this->result = Point2f(classId, confidence);
//}
